<?php
defined('_JEXEC') or die;
$row = 'odd';
$itemId = JRequest::getVar('Itemid', 0);
$pays = JRequest::getVar('pays', 0);
$icoDrapeau = JURI::root()."components/com_glycophile/asset/drapeau/";

    


?>
<div id="seriesList" class="glycoBox">
<div class="titleRow">
	<em class="nbr"><?php echo $this->total > 1 ? $this->total . ' séries' : $this->total . ' série' ; ?></em>
  <?php
    if($pays != 0){
      echo "<img style='float:left; margin-right: 10px;' width='75' height='50' src='".$icoDrapeau.$pays.".gif' />";
    }
  ?>
	<?php if(isset($this->theme->id)){ ?>
	<h2><?php echo 'Thème '. $this->theme->code .' : '. $this->theme->theme ; ?></h2>
	<?php }  
  ?>
</div>
<!--<div class="rowBoxHead">
	<div class="imgCol">Image</div>
	<div class="titleCol">Titre</div>
</div>-->
<?php
	
	foreach($this->series as $serie){

  $countSousSerie = count($serie->sseries);

    if($countSousSerie > 1)
      $showPdf = true;
    else
      $showPdf = false;
    
	$nbrSS = count($serie->sseries);
	$row = $row == 'odd' ? '' : 'odd' ;
  $icoPDf = JURI::root()."components/com_glycophile/asset/pdf.png";
  $codeSerie = strtoupper($serie->code); 
 
  $pathSerie = "components/com_glycophile/asset/images/".$serie->id_pays."/".$codeSerie."/";
  // Path de fichier PDF pour la série
 // echo "path serie : ".$pathSerie;
  $PDF_file = $pathSerie.$serie->id.".pdf";

  
  ?>
<div class="rowBox <?php echo $row ; ?>">
	<div class="imgCol">
		<a href="index.php?option=com_glycophile&view=sucres&pays=<?php echo $pays; ?>&serie=<?php echo $serie->id; ?>&Itemid=<?php echo $itemId; ?>">
		<img src="<?php echo JURI::root() ; ?>components/com_glycophile/asset/images/<?php echo $serie->id_pays.'/'.$serie->code.'/'.$serie->id.'.gif' ; ?>"  alt="<?php echo $serie->serie; ?>"/>
		</a>
    <?php 
      $user		= JFactory::getUser();
      if($user->id)
        {
        echo '<div class="page-club" style="margin-top: 10px;">Page : ';
        if($pays == '1'){
          echo $serie->pageClub;
        } else {
          echo $serie->page;
        }

        echo "</div>";
      }
    ?>

	</div>
	<div class="titleCol">
    <h2>
      <a href="index.php?option=com_glycophile&view=sucres&pays=<?php echo $pays; ?>&serie=<?php echo $serie->id; ?>&Itemid=<?php echo $itemId; ?>">
        <?php echo $serie->serie; ?>
      </a>
      <?php
      if (!$showPdf) {
         //   echo "<div class='pdf_file'>";
         if (file_exists (JPATH_SITE."/".$PDF_file)) {
            echo "<a class='pdf_file' href='".JURI::root().$PDF_file."' target='_blank' alt='".$PDF_file."' class='pdf_file'>";
            echo "<img width='32' height='32' src='".$icoPDf."' title='Download PDF' />";
            echo "</a>";
         }
          //  echo "</div>";
       }


      ?>
    </h2>
	<a target="_blank" href="index.php?option=com_glycophile&view=sucres&pays=<?php echo $pays; ?>&serie=<?php echo $serie->id; ?>&Itemid=<?php echo $itemId; ?>&tmpl=component" rel="rokbox" class="preview"><span class="icon-search"></span></a>
	</div>
	<div class="sousSeriesBox">
		<div class="rowBoxHead">
			<div class="sousSeriesRow">
				<div class="sucresCol">Sucre</div>
				<div class="variantesCol">Variantes</div>
				<div class="possedeCol">Posséde</div>
			</div>
		</div>
   
		<?php foreach($serie->sseries as $sserie){ ?>
		<div class="sousSeriesRow">
			<div class="sucresCol">        
      <?php echo $sserie->nombre_serie; ?></div>
			<div class="variantesCol">
      <?php
        echo $sserie->sous_serie;
         $PDF_file2 = $pathSerie.$serie->id.'/SS'.$sserie->id.".pdf";
      //   echo " path site : ".JPATH_SITE."/".$PDF_file2;
         if (file_exists (JPATH_SITE."/".$PDF_file2)) {
           if($showPdf){
            echo "<a class='pdf_file' href='".JURI::root().$PDF_file2."' target='_blank'  alt='".$PDF_file2."' class='pdf_file'>";
            echo "<img width='32' height='32' src='".$icoPDf."' title='Download PDF' />";
            echo "</a>";
           }       
     }
      ?>

      </div>
			<div class="possedeCol"><?php echo $sserie->calcul_serie; ?></div>
		</div>
		<?php } ?>
	</div>
</div>
<?php //  echo '<pre>'; print_r($serie); echo '</pre>'; ?>
<?php } ?>
<?php echo $this->pagination; ?>
</div>

